package cct.smartmatrix.advertisement.controller;

import cct.smartmatrix.advertisement.service.AdvertisementService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 广告列表查询
 * Created by feng yingsheng on 7/8/2017.
 */
@RestController
@RequestMapping("/advertisement")
public class AdvertisementController {

    private static final Logger logger = Logger.getLogger(AdvertisementController.class);

    @Autowired
    AdvertisementService advertisementService;

    //http://localhost:8084/advertisement/list?province=%E5%8C%97%E4%BA%AC%E5%B8%82
    @RequestMapping("/list")
    public Map<Object, Object> list(@RequestParam(name = "province", required = false) String province,
                                    @RequestParam(name = "city", required = false) String city,
                                    @RequestParam(name = "userId", required = false) String userId,
                                    @RequestParam(name = "webChannel", required = false) String webChannel,
                                    @RequestParam(name = "webCategory", required = false) String webCategory,
                                    @RequestParam(name = "refresh", required = false) String refresh,
                                    @RequestParam(name = "articleType", required = false) String articleType,
                                    @RequestParam(name = "sourceFrom", required = false) String sourceFrom,
                                    @RequestParam(name = "time", required = false) String time,
                                    @RequestParam(name = "ip", required = false) String ip,
                                    @RequestParam(name = "net", required = false) String net) {
        logger.info("there is a request for list....");
        Map<Object, Object> result = new HashMap<>();
        result.put("msg", "成功");
        result.put("code", "0");
        List<Map<Object, Object>> list = new ArrayList<>();
        Map<Object, Object> res = new HashMap<>();
        res.put("type", "1");
        String[] pic = {"http://fengyingsheng.com/wp-content/uploads/2017/04/learn-220x150.jpg"};
        res.put("pic", pic);
        res.put("jump", "http://fengyingsheng.com/?p=284");
        res.put("order", "1");
        list.add(res);

        Map<Object, Object> res2 = new HashMap<>();
        res2.put("type", "2");
        String[] pic2 = {"http://fengyingsheng.com/wp-content/uploads/2017/04/learn-220x150.jpg"};
        res2.put("pic", pic2);
        res2.put("jump", "http://fengyingsheng.com/?p=284");
        res2.put("title", "HTC WHITH新款发售");
        res2.put("order", "2");
        list.add(res2);

        Map<Object, Object> res3 = new HashMap<>();
        res3.put("type", "3");
        String[] pic3 = {"http://fengyingsheng.com/wp-content/uploads/2017/04/learn-220x150.jpg",
                "http://fengyingsheng.com/wp-content/uploads/2017/03/goodbye-e1489658751420-220x150.jpg"};
        res3.put("pic", pic3);
        res3.put("jump", "http://fengyingsheng.com/?p=259");
        res3.put("order", "3");
        list.add(res3);

        Map<Object, Object> res4 = new HashMap<>();
        res4.put("type", "4");
        String[] pic4 = {"http://fengyingsheng.com/wp-content/uploads/2017/04/learn-220x150.jpg",
                "http://fengyingsheng.com/wp-content/uploads/2017/01/vimpaire3girls-e1484451424941-220x150.jpg",
                "http://fengyingsheng.com/wp-content/uploads/2017/03/goodbye-e1489658751420-220x150.jpg"};
        res4.put("pic", pic4);
        res4.put("jump", "http://fengyingsheng.com/?p=243");
        res3.put("title", "HTC WHITH新款发售");
        res4.put("order", "4");
        list.add(res4);

        result.put("data", list);
        return result;
    }

    //http://localhost:8084/advertisement/aphomelist?province=%E5%8C%97%E4%BA%AC%E5%B8%82
    @RequestMapping("/aphomelist")
    public Map<Object, Object> aphomelist(@RequestParam(name = "province", required = false) String province,
                                    @RequestParam(name = "city", required = false) String city,
                                    @RequestParam(name = "userId", required = false) String userId,
                                    @RequestParam(name = "sourceFrom", required = false) String sourceFrom,
                                    @RequestParam(name = "time", required = false) String time,
                                    @RequestParam(name = "ip", required = false) String ip,
                                    @RequestParam(name = "net", required = false) String net) {
        logger.info("there is a request for aphomelist....");
        Map<Object, Object> result = new HashMap<>();
        result.put("msg", "成功");
        result.put("code", "0");

        List<Map<Object, Object>> list = new ArrayList<>();
        Map<Object, Object> res = new HashMap<>();
        res.put("time", "10");
        res.put("pic", "http://fengyingsheng.com/wp-content/uploads/2017/04/learn-220x150.jpg");
        res.put("jump", "http://fengyingsheng.com/?p=284");
        res.put("order", "1");
        list.add(res);

        Map<Object, Object> res2 = new HashMap<>();
        res2.put("time", "5");
        res2.put("pic", "http://fengyingsheng.com/wp-content/uploads/2017/01/vimpaire3girls-e1484451424941-220x150.jpg");
        res2.put("jump", "http://fengyingsheng.com/?p=243");
        res2.put("order", "2");
        list.add(res2);

        result.put("data", list);
        return result;
    }


}
